package com.world.business.tenbatsu.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.world.business.tenbatsu.domain.Tenbatsu;
import com.world.business.tenbatsu.domain.query.TenbatsuAddRequest;
import com.world.business.tenbatsu.domain.query.TenbatsuPageRequest;
import com.world.business.tenbatsu.domain.query.TenbatsuUpdateRequest;
import com.world.business.tenbatsu.domain.vo.TenbatsuVO;
import com.world.business.tenbatsu.service.ITenbatsuService;
import com.world.common.controller.BaseController;
import com.world.common.domain.PageResult;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 天谴 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-31
 */
@Api(tags = "天谴")
@RestController
@RequestMapping("/tenbatsu")
public class TenbatsuController extends BaseController<Tenbatsu> {

    @Resource
    private ITenbatsuService tenbatsuService;

    @ApiOperation("分页列表")
    @GetMapping("/page")
    public ResponseData<PageResult<TenbatsuVO>> page(TenbatsuPageRequest request) {
        //分页
        Page<Tenbatsu> page = startPage(request);

        IPage<TenbatsuVO> result = tenbatsuService.getPage(page, request);
        PageResult<TenbatsuVO> pageResult = getPageResult(result);
        return new SuccessResponseData<>(pageResult);
    }

    @ApiOperation("新增")
    @PostMapping("")
    public ResponseData<Long> add(@Validated @RequestBody TenbatsuAddRequest request) {
        return new SuccessResponseData<>(tenbatsuService.add(request));
    }

    @ApiOperation("修改")
    @PutMapping("")
    public ResponseData<Void> update(@Validated @RequestBody TenbatsuUpdateRequest request) {
        tenbatsuService.update(request);
        return new SuccessResponseData<>();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseData<Void> delete(@PathVariable("id") Long id) {
        tenbatsuService.delete(id);
        return new SuccessResponseData<>();
    }

}
